<?php
namespace app\home\controller;
use app\user\controller\User;
use think\Db;
class Amain extends Authinfo
{
//身边新闻列表接口
	public function newslist(){

		$map=array();
		$catid=input('catid');
		if($catid){
			$map[]=array('catid','=',$catid);
		}
		$title=input('title');
		if($title){
			$map[]=array('title','like','%'.$title.'%');
		}

		$current=input('current');
		if(!$current){
			$current=1;
		}
		$pagenums=input('pagenums');
		if(!$pagenums){
			$pagenums=10;
		}
		$nowpagenums=($current-1)*$pagenums;
		$order=input('order');
		if(!$order){
			$order='id DESC';
		}

		if($map){
			$total=Db::name('News')->where($map)->count('id');
			$info=Db::name('News')->where($map)->order($order)->limit($nowpagenums,$pagenums)->select();
		}else{
			$total=Db::name('News')->count('id');
			$info=Db::name('News')->order($order)->limit($nowpagenums,$pagenums)->select();
		}
		if($info){
			foreach ($info as $key=>$value){
				$info[$key]['create_time']=time_nianyueri($value['create_time']);
				if(!$value['pic']){
                 $info[$key]['pic']=get_one_image($value['content']);
				}
				$info[$key]['catname']=get_catname($value['catid']);
				unset($info[$key]['content']);

			}
			$datas['status']=1;
			$datas['info']=$info;
			$datas['total']=$total;
			$datas['current']=$current;
		}else{
			$datas['status']=0;
			$datas['info']='无数据！';
			$datas['total']=$total;
			$datas['current']=$current;
		}
		return json($datas);
	}

	public function  newsview(){
		 $id=input('id');
		 if($id){
            $info=Db::name('News')->where('id',$id)->find();
            if($info){
               $gx=Db::name('News')->where('id',$id)->setInc('nums');
               $info['catname']=get_catname($info['catid']);
				$info['create_time']=time_nianyueri($info['create_time']);
				$datas['status']=1;
				$datas['info']=$info;
			}else{
            	$datas['status']=0;
            	$datas['info']='无数据！';
			}
		 }else{
		 	$datas['status']=0;
		 	$datas['info']='无参数！';
		 }
		 return json($datas);
	}

	public function tenopenlist(){
		 $townsid=input('townsid');
		 if($townsid){
		 	$cuninfo=Db::name('Towns')->where('code',$townsid)->find();
		 	$cun=$cuninfo['tname'];
		 	$zhen=get_towns($cuninfo['pid']);
          $info=Db::name('Ganbuinfo')->where('zhen','=',$zhen)->where('cun','=',$cun)->where('guanxi','=','本人')->field('id,name,zhiwu,zhen,cun,sex,zzmianmao')->select();
          if($info){
             foreach ($info as $key=>$value){
             	$info[$key]['zhen']=$value['cun'];
             	$info[$key]['qinqinums']=Db::name('Ganbuinfo')->where('zhen','=',$zhen)->where('cun','=',$cun)->where('guanxi','<>','本人')->where('gxname',$value['name'])->count('id');
			 }
			  $datas['status']=1;
			  $datas['info']=$info;
		  }else{
			  $datas['status']=0;
			  $datas['info']='无数据！';
		  }
		 }
		 else{
			 $datas['status']=0;
			 $datas['info']='无参数！';
		 }
		return json($datas);
	}

	public function tenopenview(){
		$gxname=input('gxname');
		$townsid=input('townsid');
		if($gxname){
           $info=Db::name('Ganbuinfo')->where('townsid','=',$townsid)->where('gxname','=',$gxname)->field('id,name,sex,guanxi,sfid')->select();
           if($info){
              foreach ($info as $key=>$value){
              	$info[$key]['zminfo']=Db::name('Zijininfo')->where('sfid',$value['sfid'])->field('zmid')->select();
              	$info[$key]['jine']=Db::name('Zijininfo')->where('sfid',$value['sfid'])->sum('price');
              	if(!$info[$key]['jine']){
					$info[$key]['jine']=0;
				}

              	if($info[$key]['zminfo']){
                     foreach ($info[$key]['zminfo'] as $key1=>$value1){
						 $info[$key]['zminfo'][$key1]['zmtitle']=Db::name('Zijinmanage')->where('id',$value1['zmid'])->value('title');
						 $info[$key]['zminfo'][$key1]['prices']=Db::name('Zijininfo')->where('sfid','=',$value['sfid'])->where('zmid','=',$value1['zmid'])->value('price');
						 $info[$key]['zminfo'][$key1]['fftime']=Db::name('Zijininfo')->where('sfid','=',$value['sfid'])->where('zmid','=',$value1['zmid'])->value('fftime');
						 if($info[$key]['zminfo'][$key1]['fftime']){
							 $info[$key]['zminfo'][$key1]['fftime']=time_nianyueri($info[$key]['zminfo'][$key1]['fftime']);
						 }else{
							 $info[$key]['zminfo'][$key1]['fftime']='';
						 }
					 }
				}else{
					$info[$key]['zminfo']=array();

				}
				$info[$key]['sfid']=substr_replace($info[$key]['sfid'],"****",8,4);
			  }

			   $datas['status']=1;
			   $datas['info']=$info;
		   }else{
			   $datas['status']=0;
			   $datas['info']='无数据！';
		   }
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}

	public  function wozijinriqi(){
		$uid=input('uid');
		if($uid){
			$member=  Db::name('Member')->where('id',$uid)->field('sfid')->find();
			$infos=Db::name('Zijininfo')->distinct(true)->where('sfid',$member['sfid'])->field('year')->order('year DESC')->select();
			if($infos){
				$datas['status']=1;
				$datas['info']=$infos;
			}else{
				$datas['status']=0; //无信息！
				$datas['info']='无消息！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}
	//我的资金
	public function wozijin(){
		$uid=input('uid');
		$year=input('year');
		$member=  Db::name('Member')->where('id',$uid)->field('sfid')->find();

		if(!$year){

			$infos= Db::name('Zijininfo')->where('sfid',$member['sfid'])->field('year')->order('year DESC')->find();
			if($infos){
				$year=$infos['year'];
			}
		}

		if($uid){

			if(!$year){
				$datas['status']=0;//没有有效的时间
				$datas['info']='没有有效的时间';
			}else{
				$info['zongzijin']=Db::name('Zijininfo')->where('sfid',$member['sfid'])->field('price')->sum('price');
				$info['yearzijin']=Db::name('Zijininfo')->where('sfid',$member['sfid'])->where('year',$year)->field('price')->sum('price');
				$info['year']=$year;
//				dump($info);exit;
				$minfos=Db::name('Zijininfo')->where('sfid',$member['sfid'])->where('year',$year)->field('id,zmid,year,zhen,cun,price,fftime,month')->order('fftime DESC')->select();

				if($minfos){
					foreach ($minfos as $key => $value) {
						$minfos[$key]['zjmgtitle']=Db::name('Zijinmanage')->where('id',$value['zmid'])->value('title');
						$minfos[$key]['ishow']=1;
						$minfos[$key]['times']=time_yueri($value['fftime']);
					}

				}
				$info['zijinlist']=$minfos;

			}
			$datas['status']=1;
			$datas['info']=$info;
		}else{
			$datas['status']=0; //没有获取到用户信息！
			$datas['info']='没有获取到用户信息！';
		}
		return json($datas);
	}
	//资金监管 查看同村
	public function bencun(){
		//前端传的用户uid
		$uid=input('uid');
		//通过uid得到用户的townsid
		$data=Db::name('Member')->field('townsid')->where(['id'=>$uid])->find();
		$townsid=$data['townsid'];

		// 每条数据传的id值
		$zmid=input('zmid');
		$name=input('name');
		if($townsid&&$zmid){
			$towns=get_towns($townsid);
			if($name){
				$maps=array();
				$maps[]=array('name','like','%'.$name.'%');
				$maps[]=array('cun','=',$towns);
				$maps[]=array('zmid','=',$zmid);
				$info=Db::name('Zijininfo')->where($maps)->order('id DESC')->select();
			}else{
				$info=Db::name('Zijininfo')->where('cun',$towns)->where('zmid',$zmid)->order('id DESC')->select();
			}
			if($info){
				foreach ($info as $key => $value) {
					$info[$key]['fftime']=time_nianyueri($value['fftime']);
					$info[$key]['towns']=$towns;
					$info[$key]['zmidtitle']=Db::name('Zijinmanage')->where('id',$zmid)->value('title');
					$info[$key]['cmnuns']=Db::name('Member')->where('townsid',$townsid)->count();
					$info[$key]['sbtnums']=Db::name('Zijininfo')->where('cun',$towns)->where('zmid',$zmid)->field('id')->count();
					$info[$key]['sbtpries']=Db::name('Zijininfo')->where('cun',$towns)->where('zmid',$zmid)->field('price')->sum('price');

				}
			}

		}

		if($info){
			$datas['status']=1;
			$datas['info']=$info;
		}else{
			$datas['status']=0; //无补贴内容l ！
			$datas['info']='无补贴内容';
		}
		return json($datas);

	}
   public function  huimincat(){
		$info=Db::name('Hwcat')->order('sort')->select();
		if($info){
           $datas['status']=1;
           $datas['info']=$info;
		}else{
			$datas['status']=0;
			$datas['info']='无数据！';
		}
	   return json($datas);
   }

	public function huiminlist(){

		$map=array();
		$title=input('title');
		if($title){
			$map[]=array('title','like',$title.'%');
		}
		$catid=input('catid');
		if($catid){
			$map[]=array('catid','=',$catid);
		}

		$current=input('current');
		if(!$current){
			$current=1;
		}
		$pagenums=input('pagenums');
		if(!$pagenums){
			$pagenums=50;
		}
		$nowpagenums=($current-1)*$pagenums;
		$order=input('order');
		if(!$order){
			$order='id DESC';
		}
		if($map){
			$total=Db::name('Huimin')->where($map)->count('id');
			$info=Db::name('Huimin')->where($map)->order($order)->limit($nowpagenums,$pagenums)->select();
		}else{
			$total=Db::name('Huimin')->count('id');
			$info=Db::name('Huimin')->order($order)->limit($nowpagenums,$pagenums)->select();
		}
		if($info){
			foreach ($info as $key=>$value){
				$info[$key]['create_time']=time_nianyueri($value['create_time']);
				$info[$key]['zijinnums']=Db::name('Zijinmanage')->where('zcid',$value['id'])->count();
				$info[$key]['jdnums']=Db::name('Huiminjiedu')->where('zcid',$value['id'])->count();
				$info[$key]['catname']=Db::name('Hwcat')->where('id',$value['catid'])->value('title');
				unset($info[$key]['content']);

			}
			$datas['status']=1;
			$datas['info']=$info;
			$datas['total']=$total;
			$datas['current']=$current;
		}else{
			$datas['status']=0;
			$datas['info']='无数据！';
			$datas['total']=$total;
			$datas['current']=$current;
		}
		return json($datas);
	}

	public function huiminview(){
		$id=input('id');
		if($id){
			$info=Db('Huimin')->where('id',$id)->find();
			if($info){

				$info['danwei']=get_danwei($info['bid']);
				$info['tname']=get_towns($info['townsid']);


				$info['create_time']=time_nianyueri($info['create_time']);
				$info['cwtime']=time_nianyueri($info['cwtime']);
				$info['catname']=Db::name('Hwcat')->where('id',$info['catid'])->value('title');
				$info['jdlist']=Db::name('Huiminjiedu')->where('zcid',$info['id'])->field('id,title')->select();

				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}

	public function huiminjdlist(){

		$map=array();
		$title=input('title');
		if($title){
			$map[]=array('title','like',$title.'%');
		}
		$catid=input('catid');
		if($catid){
			$map[]=array('catid','=',$catid);
		}
		$zcid=input('zcid');
		if($zcid){
			$map[]=array('zcid','=',$zcid);
		}

		$current=input('current');
		if(!$current){
			$current=1;
		}
		$pagenums=input('pagenums');
		if(!$pagenums){
			$pagenums=50;
		}
		$nowpagenums=($current-1)*$pagenums;
		$order=input('order');
		if(!$order){
			$order='id DESC';
		}
		if($map){
			$total=Db::name('Huiminjiedu')->where($map)->count('id');
			$info=Db::name('Huiminjiedu')->where($map)->order($order)->limit($nowpagenums,$pagenums)->select();
		}else{
			$total=Db::name('Huiminjiedu')->count('id');
			$info=Db::name('Huiminjiedu')->order($order)->limit($nowpagenums,$pagenums)->select();
		}
		if($info){
			foreach ($info as $key=>$value){
				$info[$key]['create_time']=time_nianyueri($value['create_time']);
				$info[$key]['zctitle']=Db::name('Huimin')->where('id',$value['zcid'])->value('title');

				$info[$key]['catname']=Db::name('Hwcat')->where('id',$value['catid'])->value('title');
				unset($info[$key]['content']);

			}
			$datas['status']=1;
			$datas['info']=$info;
			$datas['total']=$total;
			$datas['current']=$current;
		}else{
			$datas['status']=0;
			$datas['info']='无数据！';
			$datas['total']=$total;
			$datas['current']=$current;
		}
		return json($datas);
	}
	public function huiminjdview(){
		$id=input('id');
		if($id){
			$info=Db('Huiminjiedu')->where('id',$id)->find();
			if($info){



				$info['create_time']=time_nianyueri($info['create_time']);
				$info['zctitle']=Db::name('Huimin')->where('id',$info['zcid'])->value('title');
				$info['catname']=Db::name('Hwcat')->where('id',$info['catid'])->value('title');

				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}

	public function zichanziyuanlist(){

		$map=array();
		$mingcheng=input('mingcheng');
		if($mingcheng){
			$map[]=array('mingcheng','like','%'.$mingcheng.'%');
		}
		$zctype=input('zctype');
		if($zctype){
			$map[]=array('zctype','=',$zctype);
		}
		$twonsid=input('twonsid');
		if($twonsid){
			$map[]=array('twonsid','=',$twonsid);
		}


		$current=input('current');
		if(!$current){
			$current=1;
		}
		$pagenums=input('pagenums');
		if(!$pagenums){
			$pagenums=50;
		}
		$nowpagenums=($current-1)*$pagenums;
		$order=input('order');
		if(!$order){
			$order='kstime DESC';
		}
		if($map){
			$total=Db::name('Zichanziyuan')->where($map)->count('id');
			$info=Db::name('Zichanziyuan')->where($map)->order($order)->limit($nowpagenums,$pagenums)->select();
		}else{
			$total=Db::name('Zichanziyuan')->count('id');
			$info=Db::name('Zichanziyuan')->order($order)->limit($nowpagenums,$pagenums)->select();
		}
		if($info){
			foreach ($info as $key=>$value){
				$info[$key]['ndate']=time_nianyueri($value['ndate']);
				$info[$key]['kstime']=time_nianyueri($value['kstime']);
				unset($info[$key]['content']);

			}
			$datas['status']=1;
			$datas['info']=$info;
			$datas['total']=$total;
			$datas['current']=$current;
		}else{
			$datas['status']=0;
			$datas['info']='无数据！';
			$datas['total']=$total;
			$datas['current']=$current;
		}
		return json($datas);
	}

	public function catlist(){
        $mark=input('mark');
        if($mark){
            $info=Db::name('Cat')->where('mark',$mark)->select();
            if($info){
                $datas['status']=1;
                $datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
	}

	public function jcopenlist()
	{

		$map = [];
		$title = input('title');
		if ($title) {
			$map[] = ['title', 'like', '%'.$title.'%'];
		}
		$catid = input('catid');
		if ($catid) {
			$map[] = ['catid', '=', $catid];
		}

		$bsid = input('bsid');
		if ($bsid) {
			$map[] = ['bsid', '=', $bsid];
		}

		$townsid = input('townsid');

		if ($townsid) {
			$map[] = ['townsid', '=', $townsid];
		}


		$current = input('current');
		if (!$current) {
			$current = 1;
		}
		$pagenums = input('pagenums');
		if (!$pagenums) {
			$pagenums = 50;
		}
		$nowpagenums = ($current - 1) * $pagenums;
		$order = input('order');
		if (!$order) {
			$order = 'id DESC';
		}
		if ($map) {
			$total = Db::name('Jcopen')->where($map)->count('id');
			$info = Db::name('Jcopen')->where($map)->field('id,title,update_time,townsid,bsid')->order($order)->limit($nowpagenums, $pagenums)->select();
		} else {
			$total = Db::name('Jcopen')->count('id');
			$info = Db::name('Jcopen')->order($order)->field('id,title,update_time,townsid,bsid')->limit($nowpagenums, $pagenums)->select();
		}
		if ($info) {
			foreach ($info as $key => $value) {
				$info[$key]['update_time'] = time_nianyueri($value['update_time']);
				$info[$key]['tname'] = get_alltowns($value['townsid']);
				$info[$key]['bsidtitle'] = Db::name('Cat')->where('id', $value['bsid'])->value('title');
			}
			$datas['status'] = 1;
			$datas['info'] = $info;
			$datas['total'] = $total;
			$datas['current'] = $current;
		} else {
			$datas['status'] = 0;
			$datas['info'] = '无数据！';
			$datas['total'] = $total;
			$datas['current'] = $current;
		}
		return json($datas);
	}

	public function jcopenview(){
		$id=input('id');
		if($id){
			$info=Db('Jcopen')->where('id',$id)->find();
			if($info){
				$info['tname']=get_towns($info['townsid']);

				$info['create_time']=time_nianyueri($info['create_time']);
				$info['update_time']=time_nianyueri($info['update_time']);
				$info['bsidtitle']=Db::name('Cat')->where('id',$info['bsid'])->value('title');

				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}

	public function cwszyuefen(){
		$townsid=input('townsid');
		if($townsid){
           $info=Db::name('Sbalance')->where('townsid',$townsid)->field('year,month,townsid')->group('year,month,townsid')->select();
           if($info){
			   $datas['status']=1;
			   $datas['info']=$info;
		   }else{
			   $datas['status']=0;
			   $datas['info']='无数据！';
		   }
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}

	public function cwshouzhiinfo(){
		$townsid=input('townsid');
		$year=input('year');
		$month=input('month');
		if($townsid && $month){
			$map=array();
			$map[]=array('townsid','=',$townsid);
			$map[]=array('year','=',$year);
			$map[]=array('month','=',$month);
			$map[]=array('rstatus','=',1);

			$info=Db::name('Proof')->where($map)->where('debitamount','>',0)->order('create_time DESC')->select();
			if($info){
				$zcprices=0;
				$srprices=0;
				foreach ($info as $key =>$value){
					if($value['debitamount']>0){
						$info[$key]['leixing']=1;
						$info[$key]['prices']=$value['debitamount'];
						$srprices=$srprices+$value['debitamount'];
					}else{
						$info[$key]['leixing']=2;
						$info[$key]['prices']=$value['creditamount'];
						$zcprices=$zcprices+$value['creditamount'];
					}
				}
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
//            if($info['debitamount']){
//            	$info['debitamountprice']=0;
//            	foreach ($info['debitamount'] as $key=>$value){
//					$info['debitamount'][$key]['create_time']=time_yueri($value['create_time']);
//					$info['debitamountprice']=$info['debitamountprice']+$value['debitamount'];
//
//				}
//			}
//			$info['creditamount']=Db::name('Proof')->where($map)->where('creditamount','>',0)->order('create_time DESC')->select();
//			if($info['creditamount']){
//				$info['creditamountprice']=0;
//				foreach ($info['creditamount'] as $key1=>$value1){
//					$info['creditamount'][$key1]['create_time']=time_yueri($value1['create_time']);
//					$info['creditamountprice']=$info['creditamountprice']+$value1['creditamount'];
//				}
//			}

		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}
    public function zichantongji(){
		$leixing=array('经营性机器设备','非经营性房屋及建筑物','非经营性办公设备','农田水利设施','道路','桥梁','其它公益设施','其他','在建工程','非经营性办公设','农田水利设施','固定资产','农业资产','机械设备','无形资产','建筑类','办公','其他类','机械类');

	    $info=array();
	    foreach ($leixing as$key =>$value){
	    	$info[$key]['title']=$value;
	    	$info[$key]['nums']=Db::name('Zichanziyuan')->where('zctype','=',$value)->count();
		}
		$datas['status']=1;
	    $datas['info']=$info;
	    return json($datas);
	}
	public function zichaninfo(){
		$map=array();
		$map[]=array('zctype','in','经营性机器设备,非经营性房屋及建筑物,非经营性办公设备,农田水利设施,道路,桥梁,其它公益设施,其他,在建工程,非经营性办公设,农田水利设施,固定资产,农业资产,机械设备,无形资产,建筑,建筑类,办公,其他类,机械类');
		$townsid=input('townsid');
		if($townsid){
          $map[]=array('townsid','=',$townsid);
		}
		$current = input('current');
		if (!$current) {
			$current = 1;
		}
		$pagenums = input('pagenums');
		if (!$pagenums) {
			$pagenums = 50;
		}
		$nowpagenums = ($current - 1) * $pagenums;
		$order = input('order');
		if (!$order) {
			$order = 'id DESC';
		}
		if ($map) {
			$total = Db::name('Zichanziyuan')->where($map)->count('id');
			$info = Db::name('Zichanziyuan')->where($map)->order($order)->limit($nowpagenums, $pagenums)->select();
		} else {
			$total = Db::name('Zichanziyuan')->count('id');
			$info = Db::name('Zichanziyuan')->order($order)->limit($nowpagenums, $pagenums)->select();
		}
		if($info){
			foreach ($info as $key=>$value){
				$info[$key]['times']=time_nianyueri($value['ndate']);
				$info[$key]['tname']=get_towns($value['townsid']);
			}
			$datas['status'] = 1;
			$datas['info'] = $info;
			$datas['total'] = $total;
			$datas['current'] = $current;
		} else {
			$datas['status'] = 0;
			$datas['info'] = '无数据！';
			$datas['total'] = $total;
			$datas['current'] = $current;
		}
		return json($datas);
	}
	public function ziyuantongji(){
		$leixing=array('资源','荒地','场地','林木资产');

		$info=array();
		foreach ($leixing as$key =>$value){
			$info[$key]['title']=$value;
			$info[$key]['nums']=Db::name('Zichanziyuan')->where('zctype','=',$value)->count();
		}
		$datas['status']=1;
		$datas['info']=$info;
		return json($datas);
	}
	public function ziyuaninfo(){
		$map=array();
		$map[]=array('zctype','in','资源,荒地,场地,林木资产');
		$townsid=input('townsid');
		if($townsid){
			$map[]=array('townsid','=',$townsid);
		}
		$current = input('current');
		if (!$current) {
			$current = 1;
		}
		$pagenums = input('pagenums');
		if (!$pagenums) {
			$pagenums = 50;
		}
		$nowpagenums = ($current - 1) * $pagenums;
		$order = input('order');
		if (!$order) {
			$order = 'id DESC';
		}
		if ($map) {
			$total = Db::name('Zichanziyuan')->where($map)->count('id');
			$info = Db::name('Zichanziyuan')->where($map)->order($order)->limit($nowpagenums, $pagenums)->select();
		} else {
			$total = Db::name('Zichanziyuan')->count('id');
			$info = Db::name('Zichanziyuan')->order($order)->limit($nowpagenums, $pagenums)->select();
		}
		if($info){
			foreach ($info as $key=>$value){
				$info[$key]['times']=time_nianyueri($value['ndate']);
				$info[$key]['tname']=get_towns($value['townsid']);
				if(!$value['zjprice']){
					$info[$key]['zjprice']=0;
				}
				if(!$value['jzprice']){
					$info[$key]['jzprice']=0;
				}
			}
			$datas['status'] = 1;
			$datas['info'] = $info;
			$datas['total'] = $total;
			$datas['current'] = $current;
		} else {
			$datas['status'] = 0;
			$datas['info'] = '无数据！';
			$datas['total'] = $total;
			$datas['current'] = $current;
		}
		return json($datas);
	}
	public  function  wenjuanlist(){
		$uid=input('uid');
		if($uid){
			$townsid=Db::name('Member')->where('id','=',$uid)->value('townsid');
			$sctownsid=Db::name('Towns')->where('code','=',$townsid)->value(['pid']);
			$info=Db::name('Shijuan')->where('townsid','=',$townsid)->whereOr('townsid','=',$sctownsid)->where('status','=',1)->select();
			if($info){
				foreach ($info as $key=>$value){
					$info[$key]['kstime']=time_format($value['kstime']);
					$info[$key]['endtime']=time_format($value['endtime']);
					$info[$key]['rennums']=Db::name('Useranswer')->where('sjid','=',$value['id'])->count();
				}
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='参数缺少！';
		}
		return json($datas);
	}

	public function kaoshiview(){
		$sjid=input('sjid');
		if($sjid){
			$info=Db::name('Shijuan')->where('id','=',$sjid)->find();
			if($info){
				if($info['tids']){
					$tm=explode('^',$info['tids']);
					$tmtitle=array();
					foreach ($tm as $key =>$value){
						$tmtitle[$key]=Db::name('Tiku')->where('id','=',$value)->find();
						$tmtitle[$key]['answer']=explode('^',$tmtitle[$key]['answer']);
					}
					$info['tmlist']=$tmtitle;
				}else{
					$info['tmlist']=array();
				}
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='参数缺少！';
		}
		return json($datas);
	}

	public function kaoshiadd(){
		$sjid=input('sjid');
		$uid=input('uid');
		$answer=input('answer');
		if($sjid && $uid){
			$tids=input('tids');
			if($tids){
				$data['tids']=$tids;
				$data['sjid']=$sjid;
				$data['answer']=$answer;
				$data['ndate']=time();
				$data['uid']=$uid;
				$data['name']=get_nickname($uid);
				$tids=explode('^',$tids);
				$answer=explode('^',$answer);
				$jifen=0;
				foreach ($tids as $key =>$value){
					$tiks=Db::name('Tiku')->where('id','=',$value)->find();
					if($tiks){
						if($tiks['answer']){
							if($tiks['answer']==$answer[$key]){
								$jifen=$jifen+$tiks['fenzhi'];
							}
						}
					}
					unset($tiks);
				}
				$data['fenshu']=$jifen;
				$czs=Db::name('Useranswer')->where('uid','=',$uid)->where('sjid','=',$sjid)->count();
				if($czs<2){
					$ids=Db::name('Useranswer')->insert($data);
					if($ids){
						$datas['status']=1;
						$datas['info']='提交成功！';
					}else{
						$datas['status']=0;
						$datas['info']='提交失败';
					}
				}else{
					$datas['status']=0;
					$datas['info']='考试次数超出';
				}


			}else{
				$datas['status']=0;
				$datas['info']='参数缺少2！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='参数缺少！';
		}
		return json($datas);
	}

	public function userkaoshi(){
		$uid=input('uid');
		if($uid){
			$info=Db::name('Useranswer')->where('uid','=',$uid)->select();
			if($info){
				foreach ($info as $key=>$value){
					$info[$key]['sjtitle']=Db::name('Shijuan')->where('id','=',$value['sjid'])->value('title');
					$info[$key]['ndate']=time_format($value['ndate']);
				}
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}

		}else{
			$datas['status']=0;
			$datas['info']='参数缺少！';
		}
		return json($datas);
	}
	public function userkaoshiview(){
		$id=input('id');
		if($id){
			$info=Db('Useranswer')->where('id',$id)->find();
			if($info){
				$info[$key]['tname']=get_alltowns(Db::name('Member')->where('id','=',$info['uid'])->value('townsid'));
				$info[$key]['sjtitle']=Db::name('Shijuan')->where('id',$info['sjid'])->value('title');



				$info['ndate']=time_nianyueri($info['ndate']);

				if($info['tids']){
					$tm=explode('^',$info['tids']);
					$danan=explode('^',$info['answer']);
					$tmtitle=array();
					foreach ($tm as $key =>$value){
						$tmtitle[$key]['neirong']=Db::name('Tiku')->where('id','=',$value)->find();
						$tmtitle[$key]['daan']=$danan[$key];
					}
					$info['tmlist']=$tmtitle;
				}else{
					$info['tmlist']=array();
				}

				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}

	public function yishijueceinfo(){
		$townsid=input('townsid');
		if($townsid){
			$map=array();
			$map[]=array('townsid','=',$townsid);
			$current = input('current');
			if (!$current) {
				$current = 1;
			}
			$pagenums = input('pagenums');
			if (!$pagenums) {
				$pagenums = 50;
			}
			$order = input('order');
			if (!$order) {
				$order = 'id DESC';
			}
			$nowpagenums = ($current - 1) * $pagenums;
			$total = Db::name('Yishijuece')->where($map)->count('id');
			$info = Db::name('Yishijuece')->where($map)->field('id,title,nums,ndate,townsid')->order($order)->limit($nowpagenums, $pagenums)->select();
			if($info){
				foreach ($info as $key=>$value){
					$info[$key]['ndate']=time_nianyueri($value['ndate']);
					$info[$key]['tname']=get_alltowns($value['townsid']);
					$info[$key]['hfnums']=Db::name('Yishijueceinfo')->where('yid','=',$value['id'])->where('status','=',1)->count();

				}
				$datas['status']=1;
				$datas['info']=$info;
				$datas['total']=$total;
				$datas['current']=$current;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
				$datas['total']=$total;
				$datas['current']=$current;
			}


		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}

		return json($datas);
	}
	public function yishijueceview(){
		$id=input('id');
		if($id){
			$info=Db('Yishijuece')->where('id',$id)->find();
			if($info){
				$gx=Db::name('Yishijuece')->where('id','=',$id)->setInc('nums');


				$info['ndate']=time_nianyueri($info['ndate']);

				$info['tname']=get_towns($info['townsid']);




				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}
	public function huifulist(){
		$yid=input('yid');
		$uid=input('uid');
		if($yid){

			$info=Db::name('Yishijueceinfo')->where('yid','=',$yid)->whereOr('status','=',1)->whereOr('uid','=',$uid)->select();
			if($info){
				foreach ($info as $key=>$value){
					$info[$key]['nickname']=get_nickname($value['uid']);
					$info[$key]['tname']=get_towns($value['townsid']);
					$info[$key]['ndate']=time_nianyueri($value['ndate']);
				}
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无信息！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}

	public function yishijuecehuifuadd(){
		$yid=input('yid');
		$content=input('content');
		$uid=input('uid');
		$townsid=input('townsid');
		if($yid && $content){
			$data['yid']=$yid;
			$data['content']=$content;
			$data['uid']=$uid;
			$data['townsid']=$townsid;
			$data['status']=2;
			$data['ndate']=time();
			$cz=Db::name('Yishijueceinfo')->where('uid','=',$uid)->find();
			if($cz){
				$tims=time();
				$newos=$tims-$cz['ndate'];
				if($newos>60){
					$ids=Db::name('Yishijueceinfo')->insert($data);
					$datas['status']=1;
					$datas['info']='提交成功';
				}else{
					$datas['status']=0;
					$datas['info']='请勿频繁提交';
				}
			}else{
				$ids=Db::name('Yishijueceinfo')->insert($data);
				$datas['status']=1;
				$datas['info']='提交成功';
			}
		}else{
			$datas['status']=0;
			$datas['info']='缺少参数！';
		}
		return json($datas);
	}
	public function ysjctuopiaoyes(){
		$uid=input('uid');
		$yid=input('yid');
		if($yid && $uid){
			$data['uid']=$uid;
			$data['yid']=$yid;
			$data['status']=1;
			$data['ndate']=time();
			$cz=Db::name('Ysjctoupiao')->where('uid','=',$uid)->where('yid','=',$yid)->find();
			if(!$cz){
				$ids=Db::name('Ysjctoupiao')->insert($data);
				$gx=Db::name('Yishijuece')->where('id','=',$yid)->setInc('goods');
				$datas['status']=1;
				$datas['info']='操作成功';
			}else{
				$datas['status']=0;
				$datas['info']='已经投票了无需投票！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}
     // 8+2资金公示
	public function eighttwo(){
		$info=array();
		$info1=array();
		//前端传的用户uid
		$uid=input('uid');
		//通过uid得到用户的townsid
		$data=Db::name('Member')->field('townsid')->where(['id'=>$uid])->find();
		$townsid=$data['townsid'];
//		$townsid=input('townsid');
		if($townsid){
			$cun=get_towns($townsid);

			$info[0]['id']=29;
			$info[0]['title']='最低生活保障';
			$info[1]['id']=30;
			$info[1]['title']='特困人员救助供养';
			$info[2]['id']=31;
			$info[2]['title']='残疾人两项补贴';
			$info[3]['id']=35;
			$info[3]['title']='困难群众丧葬补助';
			$info[4]['id']=36;
			$info[4]['title']='孤儿补贴';
			$info[5]['id']=37;
			$info[5]['title']='临时救助';
			$info[6]['id']=38;
			$info[6]['title']='老年人津贴';
			$info[7]['id']=39;
			$info[7]['title']='救灾';
			$info1[0]['id']=40;
			$info1[0]['title']='灵活就业社保补贴';
			$info1[1]['id']=41;
			$info1[1]['title']='低保转就业补贴';
			foreach ($info as $key=>$value){
				$info[$key]['nums']=Db::name('Zijininfo')->where('catid','=',$value['id'])->where('cun','=',$cun)->count();
				$data=Db::name('Zijininfo')->where('catid',$value['id'])->find();
				$info[$key]['zmid']=$data['zmid'];
			}
			foreach ($info1 as $key1=>$value1){
				$info1[$key1]['nums']=Db::name('Zijininfo')->where('catid','=',$value1['id'])->where('cun','=',$cun)->count();
				$data1=Db::name('Zijininfo')->where('catid',$value1['id'])->find();
				$info1[$key1]['zmid']=$data1['zmid'];
			}
//			dump($info);exit;
			$datas['status']=1;
			$datas['info']=$info;
			$datas['info1']=$info1;
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}

		return json($datas);

	}
	// 8+2 查看
	public function eighttwoview(){
		$catid=input('catid');
		$townsid=input('townsid');
		if($townsid && $catid){
			$cun=get_towns($townsid);
			$info=Db::name('Zijininfo')->where('catid','=',$catid)->where('cun','=',$cun)->group('zmid')->field('zmid,fftime')->select();
			if($info){
				foreach ($info as $key=>$value){
					$info[$key]['prices']=Db::name('Zijininfo')->where('catid','=',$catid)->where('cun','=',$cun)->sum('price');
					$info[$key]['fftime']=time_nianyueri($value['fftime']);
					$info[$key]['zmittle']=Db::name('Zijinmanage')->where('id','=',$value['zmid'])->value('title');
				}
				$datas['catname']=Db::name('Zijincat')->where('id','=',$catid)->value('title');
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['catname']=Db::name('Zijincat')->where('id','=',$catid)->value('title');
				$datas['status']=0;
				$datas['info']='无数据！';
			}
		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}
	//印章管控
	public function yinzhanginfo(){
		$uid=input('uid');
		$cxcode=input('cxcode');
		if($uid){
			$map=array();
			$sfid=Db::name('Member')->where('id',$uid)->value('sfid');
			if($cxcode){
				$map[]=array('cxcode','=',$cxcode);
			}else{
				$map[]=array('sfid','=',$sfid);
			}
			$info=Db::name('Yinzhang')->where($map)->select();
			if($info){
				foreach ($info as $key=>$value){
					$info[$key]['lrtime']=time_nianyueri($value['lrtime']);
					$info[$key]['sqtime']=time_nianyueri($value['sqtime']);
					$info[$key]['yxtime']=time_nianyueri($value['yxtime']);
				}
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='无数据';
			}



		}else{
			$datas['status']=0;
			$datas['info']='无参数！';
		}
		return json($datas);
	}
}
